package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.BmiAdapter;
import flc.ast.bean.MyBmiBean;
import flc.ast.databinding.ActivityBmiListBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.event.EventStatProxy;

public class BmiListActivity extends BaseAc<ActivityBmiListBinding> {

    private BmiAdapter bmiAdapter;
    private List<MyBmiBean> listShow = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.activity_bmi_list;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivBmiListBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvBmiList.setLayoutManager(new LinearLayoutManager(mContext));
        bmiAdapter = new BmiAdapter();
        mDataBinding.rvBmiList.setAdapter(bmiAdapter);
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        listShow.clear();
        List<MyBmiBean> listSp = AppSpUtils.getBmiList();
        if (listSp != null && listSp.size() > 0) {
            listShow.addAll(listSp);
            bmiAdapter.setList(listShow);
            mDataBinding.rvBmiList.setVisibility(View.VISIBLE);
            mDataBinding.tvBmiNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvBmiList.setVisibility(View.GONE);
            mDataBinding.tvBmiNoData.setVisibility(View.VISIBLE);
        }
    }

}